﻿using Ace.Application;
using Ace.Data;
using Ace.Entity.Wiki;
using Ace.Exceptions;
using Ace.IdStrategy;
using Chloe;
using Chloe.MySql;
using Chloe.SqlServer;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Ace.Application.Wiki
{
    public interface IUsersChargeItemService : IAppService
    {
        List<UsersChargeItem> GetList( );
         

        void Add(AddUsersChargeItemInput input);
        void Update(UpdateUsersChargeItemInput input);
        void Delete(string id );

        UsersChargeItem GetModel(string Id); 

        PagedData<UsersChargeItem> GetPageData(Pagination page, string keyword );
    }

    public class UsersChargeItemService : AppServiceBase<UsersChargeItem>, IUsersChargeItemService
    {
        public UsersChargeItemService(IDbContext dbContext, IServiceProvider services) : base(dbContext, services)
        {
        }

        public List<UsersChargeItem> GetList()
        {
            var q = this.Query;
             
            var ret = q.ToList();
            return ret;
        }
 

        public void Add(AddUsersChargeItemInput input)
        {
            this.InsertFromDto(input);
        }
        public void Update(UpdateUsersChargeItemInput input)
        {
            this.UpdateFromDto(input);
        }

        public UsersChargeItem GetModel(string Id)
        {
            return  this.Query.Where(a => a.Id == Id).FirstOrDefault();
        }

        public void Delete(string id)
        {
            this.DbContext.Delete<UsersChargeItem>(a => a.Id == id);
        }


        public PagedData<UsersChargeItem> GetPageData(Pagination page,  string keyword="" )
        {
            var q = this.DbContext.Query<UsersChargeItem>();
            q = q.WhereIfNotNullOrEmpty(keyword, a => a.Remark.Contains(keyword) );
             
            PagedData<UsersChargeItem> pagedData = q.TakePageData(page);
            return pagedData;
        }

         

    }

}
